package com.qidianit.mes.pro.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qidianit.mes.pojo.ProcessStep;
import com.qidianit.mes.pojo.Result;
import com.qidianit.mes.pro.mapper.ProcessStepMapper;
import com.qidianit.mes.pro.service.ProcessStepService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ Description:
 * @ Author:WuJingLei
 * @ Date: 2025/9/17 -17:00
 */
@Service
public class ProcessStepServiceImpl implements ProcessStepService {
    @Autowired
    private ProcessStepMapper stepMapper;
    @Override
    public Result<PageInfo<ProcessStep>> queryProcessSteps(Long processId,int pageNum,int size) {
        if (processId == null){
            return Result.error("processId不能为空");
        }
        //使用分页
        PageHelper.startPage(pageNum,size);
        //查询数据
        List<ProcessStep> processSteps = stepMapper.queryProcessSteps(processId);
        return Result.success(new PageInfo<>(processSteps));
    }

    @Override
    public Result<ProcessStep> getProcessStep(Long id) {
        return Result.success(stepMapper.getProcessStep(id));
    }

    @Override
    public Result<ProcessStep> saveProcessStep(ProcessStep processStep) {
        return stepMapper.saveProcessStep(processStep)>0?Result.success(processStep):Result.error("操作失败");
    }

    @Override
    public Result updateStep(ProcessStep processStep) {
        return stepMapper.updateStep(processStep)>0?Result.success():Result.error("操作失败");
    }

    @Override
    public Result deleteStep(Long id) {
        return stepMapper.deleteStep(id)>0?Result.success():Result.error("操作失败");
    }
}
